package com.xudow.app.ui;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.ColorDrawable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.PopupWindow;
import android.widget.ProgressBar;
import android.widget.Toast;

import com.nostra13.universalimageloader.core.ImageLoader;
import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener;
import com.xudow.app.Config;
import com.xudow.app.R;
import com.xudow.app.util.FileUtils;

import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

import static com.xudow.app.util.LogUtils.LOGE;
import static com.xudow.app.util.LogUtils.makeLogTag;

/**
 * 图片查看
 *
 * @author lukecheng
 */
public class ImageViewPopup extends PopupWindow {
    private static final String TAG = makeLogTag(ImageViewPopup.class);

    public ImageViewPopup(final Context context, String imageUrl) {
        super(context);

        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        final View contentView = inflater.inflate(R.layout.layout_image_view, null);

        final ProgressBar progressBar = (ProgressBar) contentView.findViewById(R.id.progressbar);
        final LinearLayout buttonLayout = (LinearLayout) contentView.findViewById(R.id.buttonLayout);
        final ImageView image = (ImageView) contentView.findViewById(R.id.image);
        Button saveButton = (Button) contentView.findViewById(R.id.save_btn);

        saveButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

            }
        });

        setContentView(contentView);

        setWidth(ViewGroup.LayoutParams.MATCH_PARENT);
        setHeight(ViewGroup.LayoutParams.MATCH_PARENT);
        setFocusable(true);
        setAnimationStyle(R.style.PopupAnimation);

        ColorDrawable dw = new ColorDrawable(0xb0000000);
        setBackgroundDrawable(dw);

        ImageLoader.getInstance().displayImage(imageUrl, image, new SimpleImageLoadingListener() {
            @Override
            public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) {
                progressBar.setVisibility(View.GONE);
                //buttonLayout.setVisibility(View.VISIBLE);
                image.setVisibility(View.VISIBLE);

                super.onLoadingComplete(imageUri, view, loadedImage);
            }
        });
    }
}
